const s = {
  v: `
          attribute vec4 a_position;
          // 平移
          uniform mat4 t_mat;
          // 缩放
          uniform mat4 s_mat;
          // 旋转
          uniform mat4 r_mat;
          void main() {
              gl_Position = t_mat * s_mat  * r_mat * a_position;
          }
      `,
  f: `
      void main() {
          gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
      }
      `,
}
// 得到着色器程序
const program = getProgram(gl, s)
// // 获取着色器程序中的变量
const a_position = gl.getAttribLocation(program, "a_position")
const t_mat = gl.getUniformLocation(program, "t_mat")
const s_mat = gl.getUniformLocation(program, "s_mat")
const r_mat = gl.getUniformLocation(program, "r_mat")
// //TODO 创建顶点数据
const positionData = new Float32Array([
  -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5,
])
// // 创建缓冲对象
const buffer = gl.createBuffer()
// // 绑定缓冲对象
gl.bindBuffer(gl.ARRAY_BUFFER, buffer)
// // 填充缓冲对象
gl.bufferData(gl.ARRAY_BUFFER, positionData, gl.STATIC_DRAW)
// // 配置变量
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0)
// // 启用变量
gl.enableVertexAttribArray(a_position)

let deg = 0
let t_x = -1
let s_x = 0.1
// 动画循环
function animate() {
  deg += 0.01
  t_x += 0.01
  s_x += 0.01

  if (t_x > 1) {
    t_x = -1
  }
  if (s_x > 1.5) {
    s_x = 0.1
  }
  const t_x_matrix = getTranslateMatrix(t_x)
  const s_x_matrix = getScaleMatrix(s_x)
  const r_x_matrix = getRotataMatrix(deg)

  gl.uniformMatrix4fv(t_mat, false, t_x_matrix)
  gl.uniformMatrix4fv(s_mat, false, s_x_matrix)
  gl.uniformMatrix4fv(r_mat, false, r_x_matrix)

  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)
  requestAnimationFrame(animate)
}
animate()
